<%@ page contentType="image/tiff; charset=gb2312" %><%@ page import="java.util.*" %><%@ page import="com.ionglobal.misc.*" %><%@ page import="java.io.*"%><%@ page import="com.ionglobal.db.*" %><%@ page import="com.ionglobal.lib.*" %><%@ page import="com.dhec.ggs.*" %><%
Sysop sysop = new Sysop();
if (session.getAttribute("sysop")!=null) {
	sysop = (Sysop) session.getAttribute("sysop");
} else {
	return;
}

Request Request = new Request(request);
String link = Request.getString("link");
int fileId = Request.getInt("fileId", 0);
if(fileId>0){
	DBI dbi = new DBI();
	try{
		AttachmentApp attApp = new AttachmentApp();
		Attachment att = attApp.getAttachment(dbi, fileId);
		if(att!=null)
			link = att.getFilePath();
	}catch(Exception e){
		e.printStackTrace();	
	}finally{
		dbi.closeAll();	
	}
}
if(link.startsWith("\\") || link.startsWith("/")){
	link=SysEnv.getFileRoot()+link.substring(1, link.length());
}
File file = new File(link);
			java.io.OutputStream out1 = response.getOutputStream(); 
			java.io.InputStream in = new java.io.FileInputStream(file);
			BufferedOutputStream bo = new BufferedOutputStream(out1); 
			BufferedInputStream bi = new BufferedInputStream(in); 
			
			int bytesRead = 0; 
			byte[] buffer = new byte[8192]; 
			while ((bytesRead = bi.read(buffer, 0, 8192)) != -1) { 
				bo.write(buffer, 0, bytesRead); 
			} 
			bo.flush(); 
			bi.close(); 
			bo.close(); 
			in.close(); 
			out1.close(); 
%>